import React, { Component } from 'react';
import { Button  } from 'react-bootstrap';
import MeetItem from './MeetItem';

class MeetList extends Component {
    constructor(props) {
        super(props);
        this.state = {
            meetArr: []
        };
    }
    
    componentDidMount() {
        fetch('https://meet.wisesoft.net.cn/getmeetingslist/')
        .then((res) => {
            if (res.ok) {
                return res.json();
            } else {
                console.log('请求房间失败');
            }
        })
        .then((json) => {
            const result = json.results;
            if (result.bCode !== 2) {
                this.setState({
                    meetArr: result.meetings
                });
            } else {
                console.log('没有房间');
            }
        })
    }

    render() {
        const MeetItemArray = this.state.meetArr.map((meet) => {
            return <MeetItem key={meet.vid} {...meet} />
        })
        return (
            <div>
                <Button bsStyle="primary" style={{ marginLeft: '15px', marginBottom: '15px' }}>+ 创建房间</Button>
                { MeetItemArray.length ? MeetItemArray : '暂时没有会议！' }
            </div>
        );
    }
}

export default MeetList;